import { HttpStatus } from '@nestjs/common';
import type {
  BaseResponseInterface,
  ResponseSuccessOptions,
  ResponseErrorOptions,
  ResponseWarningOptions,
} from '../common/interface/response';

export class Response {
  /**
   * 处理异常和返回数据
   */

  /**
   * 请求成功的返回处理函数
   */
  static success<T>(opts: ResponseSuccessOptions): BaseResponseInterface<T> {
    const { message = 'success', data = {} } = opts;

    return {
      code: HttpStatus.OK,
      message,
      data,
      z: 'xfxj',
    };
  }

  /**
   * 请求失败的返回处理函数
   */
  static error<T>(opts: ResponseErrorOptions): BaseResponseInterface<T> {
    const { message = 'error', data = {} } = opts;

    return {
      code: HttpStatus.INTERNAL_SERVER_ERROR,
      message,
      data,
      z: 'xfxj',
    };
  }

  /**
   * 处理异常的返回处理函数
   */
  static warning<T>(opts: ResponseWarningOptions): BaseResponseInterface<T> {
    const { message = 'warning', data = {} } = opts;

    return {
      code: HttpStatus.NOT_IMPLEMENTED,
      message,
      data,
      z: 'xfxj',
    };
  }
}
